package com.itheima.controller;
import com.itheima.pojo.User;
import jakarta.websocket.server.PathParam;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class RequestController {

    @RequestMapping("/hello1")
    public String hello(){
        System.out.println("hello world");
        return "hello world";
    }


    @RequestMapping("/simpleParam")
    public String simpleParam(String name, Integer age) {
        System.out.println(name + ":" + age);
        return "ok";
    }


    @RequestMapping("/simplePojo")
    public String simplePojo(User user) {
        System.out.println(user);
        return "ok";
    }


    @RequestMapping("/suchPojo")
    public String suchPojo(User user) {
        // 自动映射请求参数到 User 对象
        System.out.println(user);
        return "ok";
    }


    //集合
    @RequestMapping("/listParam")
    public String listParam(@RequestParam List<String> hobby) {

        System.out.println(hobby);
        return "ok";
    }

    //日期
    @RequestMapping("/dataTimeParam")
    public String dataTimeParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime localDateTime) {
        System.out.println(localDateTime);
        return "ok";
    }

    //json
    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user) {
        System.out.println(user);
        return "ok";
    }
    //路径参数
    @RequestMapping("/path/{id}")
    public String pathParam(@PathVariable Integer id) {
        System.out.println(id);
        return "ok";
    }

    //路径参数
    @RequestMapping("/path/{id}/{name}")
    public String pathParam2(@PathVariable Integer id,@PathVariable String name) {
        System.out.println(id+name);
        return "ok";
    }


}
